<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增平面媒体资料')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <script type="text/javascript" th:src="@{/pdata/pdata.js}"></script>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-plane-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">媒体名称：</label>
                <div class="col-sm-8">
                    <input name="mediaName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">平台：</label>
                <div class="col-sm-8">
                    <select name="platform" class="form-control m-b" th:with="type=${@dict.getType('work_platform')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">省份：</label>
                <div class="col-sm-8">
                    <select name="province" id="province" class="form-control">
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">地市：</label>
                <div class="col-sm-8">
                    <select name="city" id="city" class="form-control">
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">行业：</label>
                <div class="col-sm-8">
                    <select name="industry" class="form-control m-b" th:with="type=${@dict.getType('work_industry')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否主报：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isMaster_' + dict.dictCode}" name="isMaster" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isMaster_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单价：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系人：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input type="text" class="form-control" name="contacts" id="contacts" required>
                        <input name="contactId" id="contactId" type="hidden">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-suggest-js"/>
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "work/plane"
        $("#form-plane-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-plane-add').serialize());
            }
        }
        var testBsSuggest = $("#contacts").bsSuggest({
            url: "/work/client/query/4",
            showBtn: false,
            idField: "clientId",
            keyField: "clientName",
            effectiveFields: ["clientId", "clientName", "mobile", "QQ","createTime"],
            effectiveFieldsAlias: {clientId: "ID", clientName: "客户名称", mobile: "电话",QQ:"QQ", createTime: "登记时间"},
            showHeader: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            console.log('onSetSelectValue: ', keyword.id);
            $("#contactId").val(keyword.id);
        }).on('onUnsetSelectValue', function (e) {
            console.log("onUnsetSelectValue");
        });
        $(function () {
            var html = "<option value=''>== 请选择 ==</option>";
            $("#city").append(html);

            $.each(pdata, function (idx, item) {
                if (parseInt(item.level) == 0) {
                    html += "<option value='" + item.names + "' exid='" + item.code + "'>" + item.names + "</option>";
                }
            });
            $("#province").append(html);

            $("#province").change(function () {
                if ($(this).val() == "") return;
                $("#city option").remove();

                var code = $(this).find("option:selected").attr("exid");
                code = code.substring(0, 2);
                var html = "<option value=''>== 请选择 ==</option>";

                $.each(pdata, function (idx, item) {
                    if (parseInt(item.level) == 1 && code == item.code.substring(0, 2)) {
                        html += "<option value='" + item.names + "' exid='" + item.code + "'>" + item.names + "</option>";
                    }
                });
                $("#city").append(html);
            });
        });
    </script>
</body>
</html>